<template>
  <div class="hospital-purchase-products">
    <div class="block_purchase">
      <header>
        <span class="supplier"
          >供应商：{{ stepOneFormData.supplierVo.orgName }}</span
        >
        <span class="hospital"
          >授权医院：{{ stepOneFormData.contractVo.customerName }}</span
        >
      </header>
      <section>
        <div class="button-item">
          <el-button @click="onGetProductTemplate">
            <m-iconfont
              classify="m-pc-public"
              icon="m-pc-public_xiaz"
              size="14"
            />
            <span>模板下载</span>
          </el-button>
          <el-button @click="onOpenImportProduct">
            <m-iconfont
              classify="m-pc-public"
              icon="m-pc-public_yisb"
              size="14"
            />
            <span>模板导入</span>
          </el-button>
          <el-button @click="onOpenProductDialog">
            <m-iconfont
              classify="m-pc-public"
              icon="m-pc-public_tianj"
              size="14"
            />
            <span>添加消耗产品</span>
          </el-button>
        </div>
        <el-editable
          v-loading="productLoading"
          :columns="COLUMNS_PRODUCT"
          :payload="payload_products"
          :need-pagination="true"
          height="400"
          @reload="reloadData"
        >
          <template #default-availableQuantity="{ row }">
            <div style="color:#FF0000;">
              {{ row.availableQuantity }} （ {{ row.newMainUnit }} ）
            </div>
          </template>
          <template #default-productCount="{ row, $index }">
            <div>
              <el-input-number
                v-if="row.primaryUnitName === row.newMainUnit"
                v-model="row.productCount"
                :step="1"
                :precision="4"
                size="small"
                :min="0"
                :max="Number(row.availableQuantity) || 999999999"
                @change="onChangeCount(row, $index)"
              />
              <el-input-number
                v-else
                v-model="row.productCount"
                :step="1"
                :precision="4"
                size="small"
                :min="0"
                :max="row.viceUnitNum || 999999999"
                @change="onChangeCount(row, $index)"
              />
            </div>
          </template>
          <template #default-primaryUnitName="{ row }">
            <div>
              <el-select
                v-model="row.primaryUnitName"
                @change="getChangeButton($event, row)"
              >
                <el-option
                  v-for="item in unitOption[row.itemNum]"
                  :key="item.subUnit"
                  :label="item.subUnit"
                  :value="item.subUnit"
                >
                </el-option>
              </el-select>
              <span v-if="row.primaryUnitName !== row.newMainUnit"
                >(1{{ row.primaryUnitName }} = {{ row.unitConvertRatio
                }}{{ row.newMainUnit }})</span
              >
            </div>
          </template>
          <template #default-price="{ row, $index }">
            <div style="display: flex;">
              <el-input-number
                v-model="row.price"
                :precision="2"
                :controls="false"
                size="small"
                :max="999999999"
                @change="onChangePrice(row, $index)"
              />
              <div v-if="row.price === 0" style="padding-top: 4px;">
                <m-iconfont
                  classify="m-pc-public"
                  icon="m-pc-public_tishiwarning"
                  size="18"
                  color="red"
                />
              </div>
            </div>
          </template>
          <template #default-opt="{ row, $index }">
            <a
              style="text-decoration:none;color:#4D84FF;"
              href="javascript:;"
              @click="openSerialNumber(row)"
              >序列号</a
            >
            <a
              style="color:#FF0000;margin-left:20px;text-decoration:none;"
              href="javascript:;"
              @click="onDeleteProduct(row, $index)"
              >删除</a
            >
          </template>
          <!-- 给创建报台用的表格内表单 -->
        </el-editable>
      </section>
    </div>
    <upload
      ref="upload"
      :title-str="titleStr"
      :params="stepOneFormData"
      :payload-products="payload_products"
      @repliceProducts="repliceProductsFn"
      @complete="getUploadProducts"
    />
    <m-dialog
      title="序列号"
      :visible.sync="dialogVisible"
      width="45%"
      @refuse="GetCancelButton"
      @closeBtn="GetCancelButton"
      @confirm="GetDetermineButton"
    >
      <template #content>
        <el-editable
          :columns="ACCESSORIES_COLUMNS"
          :payload="serial_number.other"
          :height="100"
        >
          <template slot="default-index" slot-scope="scope">
            {{ scope.$index + 1 }}
          </template>
          <template #default-snCode="{ row }">
            <div>
              <el-input
                v-model="row.snCode"
                oninput="value=value.replace(/[^\d]/g,'')"
                size="small"
                :minlength="1"
                :maxlength="30"
                placeholder="请输入序列号"
                @blur="getDefocusJudgment(row)"
              />
            </div>
          </template>
          <template #default-productCount="{ row }">
            <div>
              <el-input
                v-model="row.productCount"
                oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')"
                size="small"
                placeholder="请输入数量"
                :maxlength="30"
                :minlength="1"
              />
            </div>
          </template>
          <template slot="default-ops" slot-scope="scope">
            <el-button
              style="color: red;"
              type="text"
              @click="removeCurOtherItem(scope)"
            >
              删除
            </el-button>
          </template>
        </el-editable>
        <el-link type="primary" :underline="false" @click="addSerialNumber">
          <m-iconfont
            classify="m-pc-public"
            icon="m-pc-public_tianj"
            size="14"
          />
          <span>添加序列号</span>
        </el-link>
      </template>
    </m-dialog>
  </div>
</template>

<script>
import {
  getUnitConvert,
  // queryProductPrice,
  queryProductPriceDetail
} from '@api/guoke_deepexi_interface_center_v1';
import { urlDownload } from '@const/utils';
import ElEditable from '@components/el-editable';
import upload from '@/components/hospital-consumption-order/purchase-products-list/upload';
import { ProductAddDialogService } from '~/components/hospital-consumption-order/purchase-products-list/product-dialog/product-add.dialog.module';
import * as CONSTS from './purchase-products-list.const';
// eslint-disable-next-line import/named
// eslint-disable-next-line import/extensions
import { numMulti } from '~/common';
import { IndexService } from './purchase-products-list.service';

const service = new IndexService();
export default {
  components: {
    upload,
    ElEditable
  },
  props: {
    titleStr: {
      type: String,
      default: '批发采购'
    },
    isCreateBill: {
      type: Boolean
    },
    stepOneFormData: {
      type: Object,
      default() {
        return {};
      }
    },
    option: {
      type: Object,
      default() {
        return {};
      }
    },
    products: {
      type: Array,
      default() {
        return [];
      }
    },
    type: {
      type: String,
      default: 'default'
    },
    operationType: {
      type: String,
      default() {
        return '';
      }
    },
    title: {
      type: String,
      default() {
        return '';
      }
    },
    productLoading: {
      type: Boolean
    }
  },
  data() {
    return {
      ...CONSTS,
      productList: [],
      dialogVisible: false,
      payload_products: {},
      productCodeList: [],
      itemRow: {},
      cloneRow: [],
      unitOption: {},
      unitConvertRatio: '',
      priceItem: {},
      addNumber: null,
      // viceUnitNum: 0,
      productItem: [],
      rowProductItem: [],
      buttonDisable: false,
      productNumber: 1,
      productCountItem: '',
      rowRepeatSnCode: false,
      repeatSnCode: false,
      serial_number: {
        other: {
          content: [
            {
              snCode: '', // 序列号
              productCount: ''
            } // 数量
          ]
        }
      },
      pager: {
        number: 1,
        size: 20
      },
      // 由于更新数量的动态性，下标的切换要同步。故这样搞
      index: {
        start: 1,
        end: 1
      }
    };
  },
  computed: {
    productAddDialogService() {
      return new ProductAddDialogService(this.$axios, this.$store, {
        type: this.type
      });
    }
  },
  watch: {
    products: {
      handler(val) {
        if (val !== undefined) {
          this.productList = val;
          const startIndex = (this.pager.number - 1) * this.pager.size;
          const endIndex = this.pager.number * this.pager.size;
          this.payload_products = service.getPayload(
            this.productList,
            this.pager,
            startIndex,
            endIndex
          );
        }
      },
      deep: true,
      immediate: true
    },
    option: {
      handler(val) {
        if (val !== undefined) {
          this.unitOption = val;
        }
      },
      deep: true,
      immediate: true
    }
  },
  methods: {
    // 获取单位
    getAcquisitionUnit(data) {
      const newItemList = this.payload_products.content.map(
        item => item.itemNum
      );
      const oldItemList = Object.keys(this.unitOption);
      const requestList = newItemList.filter(
        item => !oldItemList.includes(item)
      );
      if (requestList.length < 1) {
        return;
      }
      this.$axios.$post(getUnitConvert, requestList).then(res => {
        const unitsList = Object.keys(res.payload);
        unitsList.forEach(key => {
          res.payload[key].unshift({
            mainUnit: res.payload[key][0].mainUnit,
            productCode: res.payload[key][0].productCode,
            subUnit: res.payload[key][0].mainUnit,
            // unitConvertRatio: res.payload[key][0].unitConvertRatio
            unitConvertRatio: '1'
          });
          this.$set(this.unitOption, key, res.payload[key]);
        });
        this.getInitOption(
          data,
          requestList.filter(item => !unitsList.includes(item))
        );
      });
    },
    // 获取价格
    getThePrice(value, row) {
      const newRow = row;
      const params = [
        {
          orgCode: this.stepOneFormData.supplierVo.shortCode,
          cusNo: this.stepOneFormData.contractVo.accountNumber,
          prdNo: row.itemNum,
          unit: value
        }
      ];
      this.$axios.$post(queryProductPriceDetail, params).then(res => {
        const suer = res.payload;
        if (suer.length > 0) {
          newRow.price = suer[0].price;
          // newRow.productCount = suer[0].price;
          newRow.amountOfMoney = row.productCount * row.price;
          newRow.amountOfMoney = row.amountOfMoney.toFixed(2);
        }
      });
    },
    // 进页面获取价格
    getPrimaryUnitPrice(data) {
      this.buttonDisable = true;
      this.$emit('buttonDisable', this.buttonDisable);
      const params = [];
      data.forEach(item => {
        const optionItem = {
          orgCode: this.stepOneFormData.supplierVo.shortCode,
          cusNo: this.stepOneFormData.contractVo.accountNumber,
          prdNo: item.itemNum,
          unit: item.primaryUnitName
        };
        params.push(optionItem);
      });
      this.$axios
        .$post(queryProductPriceDetail, params)
        .then(res => {
          const price = res.payload;
          price.forEach((item, index) => {
            const newItem = item;
            if (newItem.price === null) {
              newItem.price = 0;
            }
            newItem.unit = params[index].unit;
            data.forEach(it => {
              const newIt = it;
              if (
                newItem.prdNo === it.itemNum &&
                newItem.unit === it.primaryUnitName
              ) {
                newIt.price = parseFloat(newItem.price);
                if (newItem.price !== null) {
                  newIt.amountOfMoney = newIt.productCount * newIt.price;
                  newIt.amountOfMoney = newIt.amountOfMoney.toFixed(2);
                }
              }
            });
          });
        })
        .finally(() => {
          this.buttonDisable = false;
          this.$emit('buttonDisable', this.buttonDisable);
        });
    },
    getChangeButton(value, row) {
      const oldRow = row;
      oldRow.viceUnitNum = 0;
      const viceUnit = this.unitOption[row.itemNum][1].subUnit;
      let quantityNum = 0;
      this.unitOption[row.itemNum].forEach(item => {
        oldRow.oldMainUnit = item.subUnit;
        oldRow.unitConvertRatio = parseFloat(item.unitConvertRatio);
        if (oldRow.newMainUnit === value) {
          quantityNum = numMulti(oldRow.productCount, 1);
          oldRow.viceUnitNum =
            numMulti(oldRow.availableQuantity, 10000) /
            numMulti(item.unitConvertRatio, 10000);
        } else {
          quantityNum = numMulti(oldRow.productCount, item.unitConvertRatio);
          oldRow.viceUnitNum =
            numMulti(oldRow.availableQuantity, 10000) /
            numMulti(item.unitConvertRatio, 10000);
          // quantityNumber = oldRow.viceUnitNum;
        }
      });
      if (oldRow.newMainUnit !== value) {
        if (quantityNum > oldRow.availableQuantity) {
          oldRow.primaryUnitName = oldRow.newMainUnit;
          this.$message({
            message: '更换单位后消耗数量将超过库存量，请先核对消耗数量',
            type: 'warning'
          });
          return;
        }
      } else if (quantityNum > oldRow.availableQuantity) {
        oldRow.primaryUnitName = viceUnit;
        // oldRow.viceUnitNum = quantityNumber;
        this.$message({
          message: '更换单位后消耗数量将超过库存量，请先核对消耗数量',
          type: 'warning'
        });
        return;
      }
      this.getThePrice(value, row);
    },
    repliceProductsFn() {
      this.productList = [];
      this.pager.number = 1;
      this.$emit('update:products', this.productList);
    },
    getUploadProducts(payload) {
      const loadProductList = payload;
      if (loadProductList.length > 0) {
        payload.forEach(element => {
          const newItem = element;
          // eslint-disable-next-line no-unused-expressions
          newItem.factoryItemNum = newItem.originalFactoryProductCode;
          newItem.itemNum = newItem.productCode;
          newItem.id = newItem.originalFactoryProductCode + newItem.batchNo;
          newItem.itemName = newItem.productName;
          newItem.availableQuantity = parseFloat(newItem.availableQuantity);
          newItem.primaryUnitName = newItem.productUnitName;
          newItem.vendorLotNumber = newItem.batchNo;
          newItem.productCount = newItem.importProductCount;
          newItem.productSnVOList = newItem.serialNumberMergeList;
          newItem.newMainUnit = newItem.primaryUnitName;
          newItem.productSnVOList.forEach(it => {
            const newIt = it;
            newIt.snCode = newIt.serialNumber;
            newIt.productCount = newIt.serialNumberSize;
          });
          this.$set(element, 'price', 0);
          this.$set(element, 'amountOfMoney', 0.0);
        });
        this.updateProductData(payload, true);
        this.getAcquisitionUnit(payload);
        this.getPrimaryUnitPrice(payload);
      }
    },
    // 前端分页逻辑
    reloadData(pager) {
      const startIndex = (pager.number - 1) * pager.size;
      const endIndex = pager.number * pager.size;
      this.payload_products = service.getPayload(
        this.productList,
        pager,
        startIndex,
        endIndex
      );
      this.pager = pager;
    },
    onDeleteProduct(row, index) {
      this.$confirm('确认删除产品吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          const startIndex = (this.pager.number - 1) * this.pager.size;
          const endIndex = this.pager.number * this.pager.size;
          this.productList.splice(startIndex + index, 1);
          this.payload_products = service.getPayload(
            this.productList,
            this.pager,
            startIndex,
            endIndex
          );
          if (this.payload_products.content.length === 0) {
            // 如果当前获取的内容为空，那么要重新获取一下数据
            this.pager.number -= 1;
            if (this.pager.number <= 0) this.pager.number = 1;
            const newStartIndex = (this.pager.number - 1) * this.pager.size;
            const newEndIndexX = this.pager.number * this.pager.size;
            this.payload_products = service.getPayload(
              this.productList,
              this.pager,
              newStartIndex,
              newEndIndexX
            );
          }
          this.$emit('update:products', this.productList);
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
    },

    onChangeCount(row) {
      const newRow = row;
      if (!row.productCount) {
        this.$nextTick(() => {
          newRow.productCount = 1;
          newRow.amountOfMoney = 1 * row.price;
          newRow.amountOfMoney = newRow.amountOfMoney.toFixed(2);
        });
      }
      this.productNumber = row.productCount;
      newRow.amountOfMoney = row.productCount * row.price;
      newRow.amountOfMoney = newRow.amountOfMoney.toFixed(2);
      this.$emit('update:products', this.productList);
    },
    onChangePrice(row) {
      const newRow = row;
      if (!row.price) {
        this.$nextTick(() => {
          newRow.price = 0;
          newRow.amountOfMoney = row.productCount * row.price;
        });
      }
      newRow.amountOfMoney = row.productCount * row.price;
      newRow.amountOfMoney = newRow.amountOfMoney.toFixed(2);
      this.$emit('update:products', this.productList);
    },
    onOpenProductDialog() {
      // 这里的formData传递完整的数据，再在子组件内整理成子级组件想要的数据格式，
      // 实际上这样做是“不好的”，但是由于数据的复杂度和混乱度，故此选择。
      // 再有一个原因是，产品搜索列表还需要一些额外的参数
      this.productAddDialogService
        .create({
          title: '添加消耗产品',
          query: {
            operationType: this.operationType,
            formData: this.stepOneFormData
          },
          confirmButtonClickHandler: (data = {}) => {
            const newData = JSON.parse(JSON.stringify(data));
            newData.forEach(element => {
              const newEle = element;
              this.$set(element, 'productCount', 1);
              this.$set(element, 'price', 0);
              this.$set(element, 'amountOfMoney', 0.0);
              newEle.newMainUnit = element.primaryUnitName;
            });
            this.updateProductData(newData);
            this.getAcquisitionUnit(newData);
            this.getPrimaryUnitPrice(newData);
          }
        })
        .mount();
    },
    getInitOption(data, list) {
      data.forEach(item => {
        if (list.includes(item.itemNum)) {
          this.$set(this.unitOption, item.itemNum, [
            {
              productCode: item.itemNum,
              mainUnit: item.primaryUnitName,
              subUnit: item.primaryUnitName,
              unitConvertRatio: '1.000000'
            }
          ]);
        }
      });
    },
    updateProductData(data, isImport) {
      this.productList = service.reConcatSelectData(
        data,
        this.productList,
        'id',
        isImport
      );
      const startIndex = (this.pager.number - 1) * this.pager.size;
      const endIndex = this.pager.number * this.pager.size;
      this.payload_products = service.getPayload(
        this.productList,
        this.pager,
        startIndex,
        endIndex
      );
      this.payload_products.content.forEach(item => {
        // this.$set(this.productList, index)
        const newItem = item;
        if (newItem.newMainUnit === newItem.primaryUnitName) {
          if (newItem.productCount < newItem.availableQuantity) {
            this.productNumber = newItem.productCount;
            newItem.amountOfMoney = newItem.price * newItem.productCount;
            newItem.amountOfMoney = newItem.amountOfMoney.toFixed(2);
            newItem.availableQuantity = item.availableQuantity;
          } else {
            newItem.productCount = newItem.availableQuantity;
            this.productNumber = newItem.productCount;
            newItem.amountOfMoney = newItem.price * newItem.productCount;
            newItem.amountOfMoney = newItem.amountOfMoney.toFixed(2);
            newItem.availableQuantity = item.availableQuantity;
          }
        }
        if (newItem.newMainUnit !== newItem.primaryUnitName) {
          newItem.newUnitConvertRatio = this.unitOption[
            newItem.itemNum
          ][1].unitConvertRatio;
          newItem.totoNumber =
            newItem.availableQuantity / newItem.newUnitConvertRatio;
          if (newItem.productCount <= newItem.totoNumber) {
            this.productNumber = newItem.productCount;
            newItem.amountOfMoney = newItem.price * newItem.productCount;
            newItem.amountOfMoney = newItem.amountOfMoney.toFixed(2);
            newItem.availableQuantity = item.availableQuantity;
          } else {
            newItem.productCount = newItem.totoNumber;
            this.productNumber = newItem.productCount;
            newItem.amountOfMoney = newItem.price * newItem.productCount;
            newItem.amountOfMoney = newItem.amountOfMoney.toFixed(2);
            newItem.availableQuantity = item.availableQuantity;
          }
        }
      });
      this.$emit('update:products', this.productList);
    },
    // 判断序列号是否重复
    getDefocusJudgment(row) {
      const newRow = row;
      this.productItem = [];
      this.rowProductItem = [];
      this.productList.forEach(item => {
        if (item.productSnVOList) {
          item.productSnVOList.forEach(it => {
            const newIt = it;
            if (newIt.id === newRow.id) {
              newIt.snCode = newRow.snCode;
            }
            this.productItem.push({
              snCode: it.snCode,
              id: it.id
            });
          });
        }
      });
      this.rowRepeatSnCode = this.serial_number.other.content.find(item => {
        if (newRow.id !== item.id) {
          return item.snCode === newRow.snCode;
        }
        return false;
      });
      this.repeatSnCode = this.productItem.find(item => {
        if (newRow.id !== item.id) {
          return item.snCode === newRow.snCode;
        }
        return false;
      });
      if (this.repeatSnCode || this.rowRepeatSnCode) {
        newRow.snCode = '';
        this.$message({
          type: 'warning',
          message: '序列号不能重复,请重新输入'
        });
      }
    },
    // 打开序列号弹窗
    openSerialNumber(row) {
      this.dialogVisible = true;
      this.itemRow = row;
      this.itemRow.productSnVOList = this.itemRow.productSnVOList || [];
      if (this.itemRow.productSnVOList.length > 0) {
        this.serial_number.other = {
          content: JSON.parse(JSON.stringify(this.itemRow.productSnVOList))
        };
        // this.serial_number.other.content.forEach(item => {
        //   const newItem = item;
        //   const newItemSnCode = this.itemRow.productSnVOList.find(it => {
        //     it.snCode === newItem.snCode;
        //   });
        //   console.log(newItemSnCode, '742------');
        //   this.itemRow.productSnVOList.forEach(it => {
        //     const newIt = it;
        //     if (newItem.snCode === '') {
        //       newIt.snCode = '';
        //     }
        //   });
        // });
      } else {
        this.serial_number.other = {
          content: [
            {
              snCode: '',
              productCount: '',
              id: Math.random()
            }
          ]
        };
      }
    },
    // 取消弹框
    GetCancelButton() {
      this.dialogVisible = false;
    },
    // 序列号确定按钮
    GetDetermineButton() {
      const mag = {
        1: `数量不得大于消耗数量`,
        2: `请添加数量`,
        3: `请添加序列号`,
        4: `数量不能为0`,
        5: `序列号行数不能大于消耗数量`
      };
      let productCount = 0;
      let type = 0;
      this.serial_number.other.content.find((item, index) => {
        productCount += Number(item.productCount);
        if (productCount > this.itemRow.productCount) {
          type = 1;
          return true;
        }
        if (item.snCode === '' && item.productCount === '') {
          this.serial_number.other.content.splice(index, 1);
          this.dialogVisible = false;
          this.itemRow.productSnVOList = this.serial_number.other.content;
          return true;
        }
        if (item.snCode === '') {
          type = 3;
          return true;
        }
        if (item.productCount === '') {
          type = 2;
          return true;
        }
        if (item.productCount === '0') {
          type = 4;
          return true;
        }
        if (
          this.serial_number.other.content.length >
          Math.ceil(this.itemRow.productCount)
        ) {
          type = 5;
          return true;
        }

        return false;
      });
      if (type) {
        this.$message({
          type: 'warning',
          message: mag[type]
        });
        return;
      }

      this.dialogVisible = false;
      this.itemRow.productSnVOList = this.serial_number.other.content;
      // this.$emit('update:products', this.productList);
    },
    // 添加序列号
    addSerialNumber() {
      const mag = {
        1: `请将信息填写完整后再添加`,
        2: `数量不得大于消耗数量`,
        3: `请添加数量`,
        4: `请添加序列号`,
        5: `数量不能为0`,
        6: `序列号行数不能大于消耗数量`
      };
      let productCount = 0;
      let type = 0;
      this.serial_number.other.content.find(item => {
        productCount += Number(item.productCount);
        if (productCount >= this.itemRow.productCount) {
          type = 2;
          return true;
        }
        if (item.snCode === '' && item.productCount === '') {
          type = 1;
          return true;
        }
        if (item.snCode === '') {
          type = 4;
          return true;
        }
        if (item.productCount === '') {
          type = 3;
          return true;
        }
        if (item.productCount === '0') {
          type = 5;
          return true;
        }
        if (
          this.serial_number.other.content.length >= this.itemRow.productCount
        ) {
          type = 6;
          return true;
        }
        return false;
      });
      if (type) {
        this.$message({
          type: 'warning',
          message: mag[type]
        });
        return;
      }
      const staticOtherItemData = {
        snCode: '', // 序列号
        productCount: '', // 数量
        id: Math.random()
      };
      this.serial_number.other.content.push(staticOtherItemData);
    },
    verifyCurFileItemDataComplete(type) {
      const len = this.serial_number[type].content.length;
      if (len === 0) {
        return true;
      }
      const curData = this.serial_number[type].content[0];
      const values = Object.values(curData);
      const flag = values.every(item => !!item);
      return flag;
    },
    // 删除一行其他附件
    removeCurOtherItem(scope) {
      this.$confirm('确定要删除序列号吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.serial_number.other.content.splice(scope.$index, 1);
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
    },
    onOpenImportProduct() {
      if (this.productList.length > 0) {
        this.$confirm(
          '确定模板导入?将清空列表已添加的消耗产品及序列号',
          '提示',
          {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }
        )
          .then(() => {
            // this.productList = [];
            this.$refs.upload.dialog_visible = true;
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消导入'
            });
          });
      } else {
        this.$refs.upload.dialog_visible = true;
      }
    },
    onGetProductTemplate() {
      urlDownload(
        'https://mt.heng-tai.com.cn/guoke-channel-aggregation-center/api/v1/files/download/xf0t3pjb801oy5j0gn1aneyovpfxb8x5.xlsx'
      );
    }
  }
};
</script>
<style lang="less">
.el-input-number {
  width: 150px;
}
.hospital-purchase-products {
  /deep/ .el-select-dropdown__item {
    width: 110px !important;
  }
  background: #ffffff;
  padding-top: 20px;
  .block_purchase {
    padding: 0 20px 0 20px;
    header {
      border: none;
      padding: 8px 20px;
      background: #f5f8ff;
      .supplier,
      .hospital {
        font-size: 16px;
        color: #4d84ff;
        line-height: 22px;
      }
      .supplier {
        margin-right: 4.2%;
      }
    }
    section {
      padding: 20px 0 20px 0;
      .button-item {
        margin-bottom: 1.1%;
        .el-button {
          color: #666 !important;
          background: #ffffff;
          padding: 11px 10px;
          border: 1px solid #ccc;
          border-radius: 3px;
        }
        .el-button:hover {
          background-color: #f4f4f4 !important;
        }
      }
      .el-select-dropdown.el-popper {
        width: 110px;
      }
      // /deep/.el-select-dropdown__list {
      //   width: 110px;
      // }
      // /deep/.el-select-dropdown__wrap.el-scrollbar__wrap {
      //   width: 110px;
      // }
    }
  }

  .el-editable {
    flex: none !important;
    min-height: 400px;
    .el-select {
      width: 70px;
      margin-right: 40px;
    }
    .el-select .el-input .el-select__caret {
      margin-top: 5px;
      font-size: 14px;
    }
    .el-input-number.is-without-controls .el-input__inner {
      width: 100px;
    }
    .el-input-number__decrease {
      height: 27px;
      line-height: 27px;
    }
    .el-input-number__increase {
      height: 27px;
      line-height: 27px;
    }
  }

  .el-dialog__header {
    border: none;
  }
  .el-link--inner {
    color: #4d84ff;
    margin-top: 10px;
  }
  .el-dialog__footer {
    // margin-top: 15px;
    border: none;
    .el-button {
      border-radius: 3px;
    }
    .el-button--primary {
      color: #ffffff !important;
      border: 1px solid #4d84ff;
      background: #4d84ff;
    }
    .el-button--primary:hover {
      background-color: #719dff !important;
      border: 1px solid #719dff;
    }
    .el-button--primary.is-disabled {
      background-color: #acc5ff !important;
      border: 1px solid #acc5ff;
    }
  }
  .m-dialog .el-dialog__header .m-dialog--title {
    margin-bottom: 0;
  }
  .el-dialog {
    .el-dialog__body {
      padding: 20px 25px 20px 25px;
      .el-editable {
        flex: none !important;
        min-height: 100px;
        // .el-input--small{
        //   border-radius: 3px;
        // }
      }
    }
  }
}
</style>
